package polimi.reds.optimizer;

import polimi.reds.NodeDescriptor;

public class TrafficLock {
	
	private NodeDescriptor n0,n1,n2;
	private boolean locked=false;
	private long lastTrafficActivity=0L;
	
	public synchronized boolean isLocked() {
		return locked;
	}
	
	public synchronized void lock(NodeDescriptor n0, NodeDescriptor n1, NodeDescriptor n2) {
		locked=true;
		this.n0=n0;
		this.n1=n1;
		this.n2=n2;
	}
	
	public synchronized void unlock() {
		locked=false;
		n0=null;
		n1=null;
		n2=null;
	}

	public NodeDescriptor getN0() {
		return n0;
	}
	
	public NodeDescriptor getN1() {
		return n1;
	}
	
	public NodeDescriptor getN2() {
		return n2;
	}
	
	public void reportQueueActivity() {
		lastTrafficActivity = System.currentTimeMillis();
	}
	
	public long getLastReportedQueueActivity() {
		return lastTrafficActivity;
	}
}